package com.zjhd.sealcutting.exception;


import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * TODO  全局异常处理类
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/24 17:22
 */


@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BizException.class)
    public ResponseResult ExceptionHandlerBizExceptionResolver(HttpServletRequest request, BizException e){
        System.out.println("自定义异常："+e.getResponseMessage()+"异常信息"+e);
        if(e.getResponseCode().equals("4006")){
            return ResultGenerator.genFailResult("4006", e.getResponseMessage());
        }else {
            return ResultGenerator.genFailResult("4005", e.getResponseMessage());
        }
    }
}
